/*
 * sql.c
 *
 *  Created on: Apr 2, 2009
 *      Author: cauan
 */

#include "sql.h"

int sql_exec(sqlite3 *db, char *statement, char *callback)
{
	char *sqlerror;

	int sql_return = sqlite3_exec( db, statement, NULL, NULL, &sqlerror);
	if (sql_return != SQLITE_OK) {
		fprintf(stderr, "		**	Error on querie: %s: %s.	**\n\n", statement, sqlite3_errmsg(db));
		fprintf(stderr, "SQL error: %s @%s:%d", sqlerror, __FILE__, __LINE__);
		free(sqlerror);
		exit(1);
	}
	sqlite3_free(sqlerror);
	return 0;
}

void sql_exit(int s)
{
	char *sqlerror;
	sqlite3_exec(db, "VACUUM;", 0, 0, &sqlerror);
	sqlite3_close(db);
	exit(s);
}
